#include "Logger.h"

Logger::Logger(string filename) {
	streamLogger = new ofstream(filename.c_str(), ofstream::app);
	if (!streamLogger->is_open()) {
		loggerActive = false;
	}
	loggerActive = true;
}

Logger::~Logger(void) {
	if (streamLogger->is_open()) {
		streamLogger->close();
	}
}

Logger& Logger::getInstance() {
	static Logger instance(LOGGER_FILE_NAME);
	return instance;
}

void Logger::operator<<(char* str) {
	if (loggerActive) {
		*streamLogger << str;
		*streamLogger << "\n";
		streamLogger->flush();
	}
}

void Logger::operator<<(string& str) {
	if (loggerActive) {
		*streamLogger << str.c_str();
		*streamLogger << "\n";
		streamLogger->flush();
	}
}
